package com.yy.utils;

import java.nio.charset.StandardCharsets;
import java.util.Base64;

/**
 * @author lyy
 * @date 2021/12/19
 */
public class Base64Util {

    public static void main(String[] args) {
        String content = "hi 歪歪";
        String encrypt = encryptToStr(content);
        System.out.println(encrypt);
        System.out.println(decryptToStr(encrypt));
    }

    public static String encryptToStr(String content){
        return Base64.getEncoder().encodeToString(content.getBytes(StandardCharsets.UTF_8));
    }

    public static byte[] encrypt(String content){
        return Base64.getEncoder().encode(content.getBytes(StandardCharsets.UTF_8));
    }

    public static byte[] decrypt(String content){
        return Base64.getDecoder().decode(content);
    }

    public static String decryptToStr(String content){
        return new String(decrypt(content));
    }
}
